package com.yunhe.mybatis.web.person;

import com.yunhe.mybatis.entity.Deparment;
import com.yunhe.mybatis.entity.User;
import com.yunhe.mybatis.service.impl.DeparmentServiceImpl;
import com.yunhe.mybatis.service.impl.UserServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/person/update")
public class UpdateServlet extends HttpServlet {
    private UserServiceImpl userService = new UserServiceImpl();
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        Integer userId = Integer .valueOf(req.getParameter("userId"));
        Integer bumen = Integer.valueOf(req.getParameter("bumen"));
        String roule = req.getParameter("roule");

        User user = new User();
        user.setRoule(roule);
        user.setId(userId);

        Deparment deparment = new Deparment();
        deparment.setId(bumen);

        //关联的两个表
        user.setDeparment(deparment);

        userService.updateper(user);

        req.getRequestDispatcher("/success.jsp").forward(req,resp);
    }

}
